﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace DHQGHN.PM0.Models.Admin
{
    public class HhRelationshipModel
    {
        public Int64 HH_RELATIONSHIP_ID { get; set; }

        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập Tên mối quan hệ")]
        [Remote("CheckExistHhName", "HhRelationship", ErrorMessage = "Tên mối quan hệ đã tồn tại", HttpMethod = "POST", AdditionalFields = "HH_RELATIONSHIP_ID")]
        [StringLength(50, ErrorMessage = "Độ dài tối đa là 50 ký tự")]
        [Display(Name = "Tên quan hệ")]
        public string NAME { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập Mã mối quan hệ")]
        [Remote("CheckExistHhCode", "HhRelationship", ErrorMessage = "Mã mối quan hệ đã tồn tại", HttpMethod = "POST", AdditionalFields = "HH_RELATIONSHIP_ID")]
        [StringLength(2, ErrorMessage = "Độ dài tối đa là 2 ký tự")]
        [RegularExpression(@"^[a-zA-Z0-9]+[a-zA-Z0-9_]*[a-zA-Z0-9]*$", ErrorMessage = "Mã không đúng định dạng")]
        [Display(Name = "Mã quan hệ")]
        public string CODE { get; set; }
        [Display(Name = "Mô tả")]
        [StringLength(150, ErrorMessage = "Độ dài tối đa là 150 ký tự")]
        public string DESCRIPTIONS { get; set; }
        public int DELETED { get; set; }
        public int RecordCount { get; set; }

        public const string FIELD_HH_RELATIONSHIP_ID = "HH_RELATIONSHIP_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string FIELD_RECORD_COUNT = "RecordCount";

        public HhRelationshipModel()
        {

        }

        public HhRelationshipModel(DAL.Models.Admin.HhRelationshipModel hhModel)
        {
            // TODO: Complete member initialization
            HH_RELATIONSHIP_ID = hhModel.HH_RELATIONSHIP_ID;
            CODE = hhModel.CODE;
            NAME = hhModel.NAME;
            DESCRIPTIONS = hhModel.DESCRIPTIONS;
            DELETED = hhModel.DELETED;
            RecordCount = hhModel.RecordCount;
        }

        internal DAL.Models.Admin.HhRelationshipModel toDALModel()
        {
            DAL.Models.Admin.HhRelationshipModel hhModel = new DAL.Models.Admin.HhRelationshipModel
            {
                HH_RELATIONSHIP_ID = HH_RELATIONSHIP_ID,
                CODE = CODE,
                NAME = NAME,
                DESCRIPTIONS = DESCRIPTIONS,
                DELETED = DELETED,
                RecordCount = RecordCount
            };
            return hhModel;
        }
    }
}
